/**
 * FileName: ResultData
 * Author: Wb
 * Date: 2025/9/24 14:10
 * Description:
 * History:
 */
package org.test.device.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈统一的返回方法〉
 *
 * @author Wb
 * @create 2025/9/24
 * @since 1.0.0
 */
@Data
public class ResultData {

    //返回状态码
    private Integer code;

    //返回信息
    private String message;

    private String type;

    //返回数据
    private Map<String,Object> data=new HashMap<>();


    public ResultData(Integer code, String message, Map<String, Object> data) {
        this.code = code;
        this.message = message;
        if (data != null) {
            this.data = data;
        }
    }

    public ResultData(String message, Map<String, Object> data) {
        this.code = Math.toIntExact(BusinessCode.SUCCESS.getCode());
        this.type = BusinessCode.SUCCESS.name();
        this.message = message;
        this.data = data;
    }

    public ResultData(String message) {
        this.code = Math.toIntExact(BusinessCode.SUCCESS.getCode());
        this.type = BusinessCode.SUCCESS.name();
        this.message = message;
    }

    public ResultData(String message, String type) {
        this.code = Math.toIntExact(BusinessCode.SUCCESS.getCode());
        this.type = type;
        this.message = message;
    }

    public ResultData() {
        this.code = Math.toIntExact(BusinessCode.SUCCESS.getCode());
        this.type = BusinessCode.SUCCESS.name();
    }

    public static ResultData pageResponse(List<?> list, long total, long pages, int pageNum) {
        ResultData resultData = new ResultData();
        resultData.getData().put("records", list);
        resultData.getData().put("total", total);
        resultData.getData().put("pages", pages);
        resultData.getData().put("pageNum", pageNum);
        return resultData;
    }
}